<template>
	<view class="income-info">
		<view class="c-row-box">
			<view class="c-row-head">
				<view class="c-row-title">收款信息</view>
			</view>
			<view class="c-row-item">
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title"><text style="color: red;">*</text>收据编号</view>
						<view class="col-text">
							<input type="text" @blur="checkIncome" v-model="incomeParams.receivable_no" :disabled="isPreview"
								placeholder="请输入" />
						</view>
					</view>
				</view>
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title"><text style="color: red;">*</text>收款方式</view>
						<view class="col-text">
							<picker mode="selector" :range="paymentList" range-key="title" @change="incomePaymentChange"
								:disabled="isPreview">
								<view>{{incomeParams.income_payment_text}}</view>
							</picker>
						</view>
					</view>
				</view>
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">
							<text style="color: red;">*</text>
							收款性质
						</view>
                        <view class="col-text" v-if="type=='fn'">
							<view>{{ selectedIncomeType }}</view>
						</view>
						<view class="col-text" v-else>
							<picker mode="selector" :range="incomeOrderList" range-key="title" @change="incomeOrderChange" :disabled="isPreview">
								<view>{{ selectedIncomeType }}</view>
							</picker>
						</view>
                      
					</view>
				</view>
				<view class="c-row c-row-list" v-if="orderParams.order_nature != 3">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title"><text style="color: red;">*</text>收款金额</view>
						<view class="col-text">
							<input type="digit" @blur="checkIncome" v-model="incomeParams.wedding_income_item_price" @input="getTailMoney"
								:disabled="isPreview" placeholder="请输入" />
						</view>
					</view>
				</view>
				<view class="c-row c-row-list" v-else>
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title"><text style="color: red;">*</text>收款金额</view>
						<view class="col-text">
							<input type="digit" @blur="checkIncome" v-model="incomeParams.wedding_income_item_price" :disabled="isPreview"
								placeholder="请输入" />
						</view>
					</view>
				</view>
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title"><text style="color: red;">*</text>收款时间</view>
						<view class="col-text">
							<picker mode="date" :start="startDate" :end="endDate" @change="incomeDateChange"
								:disabled="isPreview">
								<view>{{incomeParams.wedding_income_date}}</view>
							</picker>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import dictionary from '@/utils/dictionary.js';
import request from '@/utils/request.js';
	export default {
		props: {
			isPreview: {
				type: Boolean,
				default () {
					return false
				}
			},
			incomeParams: {
				type: Object,
				default () {
					return {}
				}
			},
			orderParams: {
				type: Object,
				default () {
					return {}
				}
			},
			paymentList: {
				type: Array,
				default () {
					return []
				}
			},
			incomeNature: {
				type: Number,
				default () {
					return null
				}
			},
			incomeType: {
				type: String,
				default () {
					return ''
				}
			},
			startDate: {
				type: String,
				default () {
					return ''
				}
			},
			endDate: {
				type: String,
				default () {
					return ''
				}
			}
		},
		computed: {
        selectedIncomeType: function () {
            return dictionary.getPickerTitle('exchangeTypeList', this.incomeParams.income_type, '请选择');
        }
    },
		data() {
			return {
				incomeNatureList: {
					1: '订单',
					2: '返佣单',
					3: '定金',
					4: '意向金',
					7: '宝宝宴',
					8: '酒店服务',
					9: '加桌',
					10: '加菜',
					11: '婚庆增项',
					12: '婚宴增项'
				},
				incomeOrder: [{
						id: 1,
						title: '定金'
					},
					{
						id: 2,
						title: '全款'
					}
				],
				incomeOrderList: [{
						id: 1,
						title: '定金'
					},
					{
						id: 2,
						title: '全款'
					}
				],
				type:"",
			};
		},
		mounted() {
			this.incomeOrderList = uni.getStorageSync('allPicker').exchangeTypeList;
		},
		beforeMount() {
        this.dictionary = dictionary;
    },
		methods: {
					//验证收款性质
		getIncomeNature(type,value){
            console.log(value)
            let _this =this;
			//创建订单
			if(type=='order'){
				_this.incomeOrderList = _this.incomeOrder
			}
			// 收款
			if(type=='income'){
				_this.incomeOrderList = _this.incomeOrderList
			}
			//自定义
			if(type=='fn'){
                _this.type = type;
				console.log(this.incomeParams)
                _this.incomeParams.income_type =value[0].id
				_this.incomeOrderList = value
			}
		},
			        // 检查收款编号
		verificationCode(collection_code) {
			if (collection_code != '') {
				request.request({
					url: '/api/order.collection_code/unique',
					showLoading: true,
					token: true,
					data: {
						collection_code: collection_code
					},
					success(res) {
						if (res.code == 200) {
							uni.showToast({
								icon: 'none',
								title: res.msg,
								duration: 3000
							});
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg,
								duration: 3000
							});
						}
					}
				});
			}
		},
        checkIncome(){
            let _this =this;
        	let incomePrice = _this.incomeParams.wedding_income_item_price;
            if(incomePrice>0){
                _this.verificationCode(_this.incomeParams.receivable_no)
            }
        },		
			// 收款日期
			incomeDateChange(e) {
				this.incomeParams.wedding_income_date = e.target.value;
			},

			// 收款方式 
			incomePaymentChange(e) {
				let index = e.target.value;
				this.incomeParams.wedding_income_payment = this.paymentList[index].id;
				this.incomeParams.income_payment_text = this.paymentList[index].title;
			},

			// 当是订单时
			incomeOrderChange(e) {
				let index = e.target.value;
				if (this.incomeType == '13') {
					this.incomeParams.income_type_text = this.incomeOrderList[index].title;
					this.incomeParams.income_type = this.incomeOrderList[index].id;
				} else {
					this.incomeParams.income_type_text = this.incomeOrder[index].title;
					this.incomeParams.income_type = this.incomeOrder[index].id;
				}
			},

			// 自动计算尾款
			getTailMoney(e) {
				this.orderParams.earnest_money = e.detail.value;
				this.$emit('getTailMoney')
			}
		}
	}
</script>
<style lang="less">
@import url('../../components/common.less');
@import url('../common/common.less');
</style>
